#ifndef SIGNALDATA_H
#define SIGNALDATA_H
#include <iostream>

#include <QMetaEnum>
#include <QObject>
#include <QVariant>
#include <QMap>
#include <QString>

#define debugx(x) qDebug().noquote() <<__FILE__<<__LINE__ <<Q_FUNC_INFO<<x
#define infoX(x) qInfo().noquote() <<__FILE__<<__LINE__ <<Q_FUNC_INFO<<x
#define criticalX(x) qCritical().noquote() <<__FILE__<<__LINE__ <<Q_FUNC_INFO<<x

/**
 *SignalData封装体
 **/
class SignalData : public QObject
{
    Q_OBJECT

public:
    enum Type
    {
        Sys,
        MainWinClose,//主窗体关闭
        Pluginloaded,
        PluginUnload,//卸载插件，通知某插件，将要卸载该插件：让插件释放内存等资源。
        SysPluginUnload_Ack,//插件应答：已完成卸载准备。

        Normal
    };

    Q_ENUM(Type)

    QString from;
    QString to;
    Type type=Normal;
    QMap<QString,QVariant> map;
    void *data = nullptr;

    SignalData(){ }
    SignalData(Type typeA){ type=typeA;}
    SignalData(Type typeA,void *dataA){ type=typeA;data=dataA;}
    SignalData(QString fromA,QString toA){ from=fromA;to=toA;}

    friend  QDataStream &operator<<(QDataStream & ds, const SignalData &msg)
    {ds<<"from:" << msg.from << "  to:" << msg.to<<"  type: " << QMetaEnum::fromType<SignalData::Type>().key(msg.type) ;
        return ds;}

    friend inline QDebug operator<<(QDebug out, const SignalData &msg)
    {
        out <<"from:" << msg.from << "  to:" << msg.to<<"  type: " << QMetaEnum::fromType<SignalData::Type>().key(msg.type) ;
        return out;
    }

    QString toString(){return "from:" +from + "  to:" +to+"  type: " +QMetaEnum::fromType<SignalData::Type>().key(type) ;}

};


Q_DECLARE_METATYPE(SignalData);  //确保类型可以通过信号槽传递





#endif // SIGNALDATA_H
